/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.openams.server.entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author mike
 */
@Entity
@Table(name = "datasettemplateassignments", uniqueConstraints = {
    @UniqueConstraint(columnNames = {"DatasetTemplateID", "AttributeName"}),
    @UniqueConstraint(columnNames = {"DatasetTemplateAssignmentID"})})
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "DatasetTemplateAssignment.findAll", query = "SELECT d FROM DatasetTemplateAssignment d"),
    @NamedQuery(name = "DatasetTemplateAssignment.findByDatasetTemplateAssignmentID", query = "SELECT d FROM DatasetTemplateAssignment d WHERE d.datasetTemplateAssignmentID = :datasetTemplateAssignmentID"),
    @NamedQuery(name = "DatasetTemplateAssignment.findByDatasetTemplateAssignmentGlobalID", query = "SELECT d FROM DatasetTemplateAssignment d WHERE d.datasetTemplateAssignmentGlobalID = :datasetTemplateAssignmentGlobalID"),
    @NamedQuery(name = "DatasetTemplateAssignment.findByAttributeName", query = "SELECT d FROM DatasetTemplateAssignment d WHERE d.attributeName = :attributeName"),
    @NamedQuery(name = "DatasetTemplateAssignment.findByAttributeType", query = "SELECT d FROM DatasetTemplateAssignment d WHERE d.attributeType = :attributeType"),
    @NamedQuery(name = "DatasetTemplateAssignment.findByRequired", query = "SELECT d FROM DatasetTemplateAssignment d WHERE d.required = :required"),
    @NamedQuery(name = "DatasetTemplateAssignment.findByAttributeDescription", query = "SELECT d FROM DatasetTemplateAssignment d WHERE d.attributeDescription = :attributeDescription"),
    @NamedQuery(name = "DatasetTemplateAssignment.findByExpirationStrategy", query = "SELECT d FROM DatasetTemplateAssignment d WHERE d.expirationStrategy = :expirationStrategy")})
public class DatasetTemplateAssignment implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "DatasetTemplateAssignmentID", nullable = false)
    private Integer datasetTemplateAssignmentID;
    @Size(max = 36)
    @Column(name = "DatasetTemplateAssignmentGlobalID", length = 36)
    private String datasetTemplateAssignmentGlobalID;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "AttributeName", nullable = false, length = 45)
    private String attributeName;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 12)
    @Column(name = "AttributeType", nullable = false, length = 12)
    private String attributeType;
    @Basic(optional = false)
    @NotNull
    @Column(name = "Required", nullable = false)
    private boolean required;
    @Size(max = 256)
    @Column(name = "AttributeDescription", length = 256)
    private String attributeDescription;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 9)
    @Column(name = "ExpirationStrategy", nullable = false, length = 9)
    private String expirationStrategy;
    @JoinColumn(name = "ReferenceDatasetTemplateHierarchyID", referencedColumnName = "DatasetTemplateHierarchyID")
    @ManyToOne(fetch = FetchType.LAZY)
    private DatasetTemplateHierarchy referenceDatasetTemplateHierarchyID;
    @JoinColumn(name = "MetaDatasetTemplateID", referencedColumnName = "DatasetTemplateID")
    @ManyToOne(fetch = FetchType.LAZY)
    private DatasetTemplate metaDatasetTemplateID;
    @JoinColumn(name = "DatasetTemplateID", referencedColumnName = "DatasetTemplateID", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private DatasetTemplate datasetTemplateID;
    @OneToMany(mappedBy = "datasetTemplateAssignmentID", fetch = FetchType.LAZY)
    private Collection<DatasetInstanceAssignment> datasetInstanceAssignmentCollection;

    public DatasetTemplateAssignment() {
    }

    public DatasetTemplateAssignment(Integer datasetTemplateAssignmentID) {
        this.datasetTemplateAssignmentID = datasetTemplateAssignmentID;
    }

    public DatasetTemplateAssignment(Integer datasetTemplateAssignmentID, String attributeName, String attributeType, boolean required, String expirationStrategy) {
        this.datasetTemplateAssignmentID = datasetTemplateAssignmentID;
        this.attributeName = attributeName;
        this.attributeType = attributeType;
        this.required = required;
        this.expirationStrategy = expirationStrategy;
    }

    public Integer getDatasetTemplateAssignmentID() {
        return datasetTemplateAssignmentID;
    }

    public void setDatasetTemplateAssignmentID(Integer datasetTemplateAssignmentID) {
        this.datasetTemplateAssignmentID = datasetTemplateAssignmentID;
    }

    public String getDatasetTemplateAssignmentGlobalID() {
        return datasetTemplateAssignmentGlobalID;
    }

    public void setDatasetTemplateAssignmentGlobalID(String datasetTemplateAssignmentGlobalID) {
        this.datasetTemplateAssignmentGlobalID = datasetTemplateAssignmentGlobalID;
    }

    public String getAttributeName() {
        return attributeName;
    }

    public void setAttributeName(String attributeName) {
        this.attributeName = attributeName;
    }

    public String getAttributeType() {
        return attributeType;
    }

    public void setAttributeType(String attributeType) {
        this.attributeType = attributeType;
    }

    public boolean getRequired() {
        return required;
    }

    public void setRequired(boolean required) {
        this.required = required;
    }

    public String getAttributeDescription() {
        return attributeDescription;
    }

    public void setAttributeDescription(String attributeDescription) {
        this.attributeDescription = attributeDescription;
    }

    public String getExpirationStrategy() {
        return expirationStrategy;
    }

    public void setExpirationStrategy(String expirationStrategy) {
        this.expirationStrategy = expirationStrategy;
    }

    public DatasetTemplateHierarchy getReferenceDatasetTemplateHierarchyID() {
        return referenceDatasetTemplateHierarchyID;
    }

    public void setReferenceDatasetTemplateHierarchyID(DatasetTemplateHierarchy referenceDatasetTemplateHierarchyID) {
        this.referenceDatasetTemplateHierarchyID = referenceDatasetTemplateHierarchyID;
    }

    public DatasetTemplate getMetaDatasetTemplateID() {
        return metaDatasetTemplateID;
    }

    public void setMetaDatasetTemplateID(DatasetTemplate metaDatasetTemplateID) {
        this.metaDatasetTemplateID = metaDatasetTemplateID;
    }

    public DatasetTemplate getDatasetTemplateID() {
        return datasetTemplateID;
    }

    public void setDatasetTemplateID(DatasetTemplate datasetTemplateID) {
        this.datasetTemplateID = datasetTemplateID;
    }

    @XmlTransient
    public Collection<DatasetInstanceAssignment> getDatasetInstanceAssignmentCollection() {
        return datasetInstanceAssignmentCollection;
    }

    public void setDatasetInstanceAssignmentCollection(Collection<DatasetInstanceAssignment> datasetInstanceAssignmentCollection) {
        this.datasetInstanceAssignmentCollection = datasetInstanceAssignmentCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (datasetTemplateAssignmentID != null ? datasetTemplateAssignmentID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof DatasetTemplateAssignment)) {
            return false;
        }
        DatasetTemplateAssignment other = (DatasetTemplateAssignment) object;
        if ((this.datasetTemplateAssignmentID == null && other.datasetTemplateAssignmentID != null) || (this.datasetTemplateAssignmentID != null && !this.datasetTemplateAssignmentID.equals(other.datasetTemplateAssignmentID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.openams.server.entity.DatasetTemplateAssignment[ datasetTemplateAssignmentID=" + datasetTemplateAssignmentID + " ]";
    }
    
}
